package com.obligatorio.faces.utils;

import javax.faces.event.PhaseEvent;
import javax.faces.event.PhaseId;
import javax.faces.event.PhaseListener;

import org.apache.log4j.Logger;

public class DefaultPhaseListener implements PhaseListener {

	private static final long serialVersionUID = -1065005858605121693L;
	private static final String loginPage = "login.xhtml";
	private static final Logger log = Logger
			.getLogger(DefaultPhaseListener.class.getName());

	@Override
	public void afterPhase(PhaseEvent event) {
	}

	@Override
	public void beforePhase(PhaseEvent event) {
		// FacesContext context = event.getFacesContext();
		// ExternalContext ext = context.getExternalContext();
		// HttpSession session = (HttpSession) ext.getSession(false);
		// boolean newSession = (session == null) || (session.isNew());
		// boolean postback = !ext.getRequestParameterMap().isEmpty();
		// boolean timedout = postback && newSession;
		// log.info("newSession : " + newSession);
		// log.info("postback : " + postback);
		// log.info("timedout : " + timedout);

	
		// if (timedout) {
		// Application app = context.getApplication();
		// ViewHandler viewHandler = app.getViewHandler();
		// UIViewRoot view = viewHandler.createView(context, "/" + loginPage);
		// log.info("view : " + view);
		//
		// context.setViewRoot(view);
		// context.renderResponse();
		// try {
		// viewHandler.renderView(context, view);
		// context.responseComplete();
		// } catch (Throwable t) {
		// // opcionalmente
		// throw new FacesException("La session ha expirado.", t);
		// }
		// }
	}

	@Override
	public PhaseId getPhaseId() {
		return PhaseId.RESTORE_VIEW;
	}
}